package com.demo.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

//用注解方式定义切面、切入点和通知(最简版本,切入点表达式重复出现在每个通知中)
@Aspect
public class AnnoAspect1 {
    //前置通知
    @Before("execution( * com.demo.service.UserService.insert(..))")
    public void before() {
        System.out.println("这是前置通知(执行准备或预检任务)");
    }

    //返回通知
    @AfterReturning("execution( * com.demo.service.UserService.*(..))")
    public void afterReturning() {
        System.out.println("这是返回通知!");
    }

    //环绕通知
    @Around("execution( * com.demo.service.UserService.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("这是环绕通知之前的部分！");
        //调用目标方法
        Object object = point.proceed();
        System.out.println("这是环绕通知之后的部分！");
        return object;
    }


    //后置通知
    @After("execution( * com.demo.service.UserService.*(..))")
    public void after() {
        System.out.println("这是后置通知！");
    }
}